package city.spring.modules.reception.service.impl;

import city.spring.modules.reception.entity.OldmanVolunteerInfoEntity;
import city.spring.modules.reception.repository.OldmanVolunteerInfoRepository;
import city.spring.modules.reception.service.OldmanVolunteerInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：志愿者信息
 *
 * @author pxm
 * @date 2020-07-01 09:54:20
 */
@CacheConfig(cacheNames = {OldmanVolunteerInfoServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Throwable.class)
@Service
public class OldmanVolunteerInfoServiceImpl extends ServiceImpl<OldmanVolunteerInfoRepository, OldmanVolunteerInfoEntity> implements OldmanVolunteerInfoService {
//    private final OldmanVolunteerInfoService oldmanVolunteerInfoService;
//    private final OldmanServiceRecordService oldmanServiceRecordService;
//
//    public OldmanVolunteerInfoServiceImpl(OldmanVolunteerInfoService oldmanVolunteerInfoService, OldmanServiceRecordService oldmanServiceRecordService) {
//        this.oldmanVolunteerInfoService = oldmanVolunteerInfoService;
//        this.oldmanServiceRecordService = oldmanServiceRecordService;
//    }

    @Override
    public void saveOldmanVolunteerInfo(OldmanVolunteerInfoEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateOldmanVolunteerInfo(OldmanVolunteerInfoEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改

        // 志愿者更新手机号时，服务记录表里的手机号随之更新
//        OldmanVolunteerInfoEntity oldmanVolunteerInfoEntity = oldmanVolunteerInfoService.getById(entity.getId());
//        if(!entity.getPhone().equals(oldmanVolunteerInfoEntity.getPhone())){
//        }
        boolean update = updateById(entity);
        if (!update) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteOldmanVolunteerInfo(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteOldmanVolunteerInfo(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }
}